﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using FlexySys.Common.Items;

namespace Web.FlexyUserControls
{
    public partial class DocumenContentControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_Init(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            var template = XElement.Parse(@"<Template>
                                                <Controls>
                                                    <Control Type='Upload' ID='Up1'/>
                                                    <Control Type='CommandButton' CommandType='Save' ID='MyID' Width='150px' Text='New Save Button'/>
                                                    <Control Type='Button' CommandType='Save' ID='CustomMyID' Text='Custom Save Button'/>
                                                    <Control Type='HtmlTable'> 
                                                        <Control Type='HtmlRow'>
                                                            <Control Type='HtmlColumn'>
                                                                <Control Type='Label' Text='My label' Width='300px'/>
                                                            </Control>
                                                            <Control Type='HtmlColumn'>
                                                                <Control Type='TextBox' ID='TextID1' Enabled='true' Width='300px'/>
                                                            </Control>
                                                            <Control Type='HtmlColumn'>
                                                                <Control Type='TextBox' ID='TextID2' Enabled='true' Width='300px'/>
                                                            </Control>
                                                         </Control>
                                                     </Control>
                                                 </Controls>
                                            </Template>");

            var dataSource = XElement.Parse(@"<Document GUID='966f7e80-f462-440f-883b-2982488fa92f'>
	                                          <Data>
		                                          <Item ID='Up1'>
			                                          <Value/>
		                                          </Item>
		                                          <Item ID='TextID1'>
			                                          <Value></Value>
		                                          </Item>
                                                <Item ID='TextID2'>
			                                          <Value></Value>
		                                          </Item>
	                                           </Data>
                                          </Document>");


            render = new DocumentRender
            {
                Page = this.Page,
                Template = template,
                Data    = new DocumentData(dataSource),
                Factory = new ControlFactory { Page = this.Page  },
                AddControl = this.PlaceHolder1.Controls.Add

            };

            render.Render();


            //}

        }

        public XElement  DocumentData {
            get { return render.GetDataSource(); }
        } 
        protected  IDocumentRender render { get; set; }
        public Guid DocumentID { get; set; }
    }
}